/**
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *	
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package com.brightcove.android.oneplanet;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

import com.brightcove.mobile.mediaapi.model.Playlist;
import com.brightcove.mobile.mediaapi.model.Video;

/**
 * A helper class for dealing with the content returned from 
 * api.brightcove.com.
 */
public class AndroidPlaylist implements Serializable {
	public static final String PLAYLIST="playlist";

	private static final long serialVersionUID = 1L;
	
	private String name;
	private long[] videoIds;
	private ArrayList<String> videoNames;
	private ArrayList<String> thumbnailUrls;
	
	public AndroidPlaylist(Playlist playlist) {
		name = playlist.getName();
    	videoNames = new ArrayList<String>();
    	thumbnailUrls = new ArrayList<String>();
    	for (Iterator<Video> it = playlist.getVideos().iterator(); it.hasNext();) {
    		Video video = it.next();
    		videoNames.add(video.getName());
    		thumbnailUrls.add(video.getThumbnailUrl());
    	}

    	// convert Long ArrayList to long[]
    	videoIds = new long[playlist.getVideoIds().size()];
    	int counter = 0;
    	for (Iterator<Long> it = playlist.getVideoIds().iterator(); it.hasNext();) {
			Long videoId = it.next();
			videoIds[counter++] = videoId.longValue();
		}
	}

	/**
	 * @return the playlist name.
	 */
	public String getName() {
		return name;
	}
	
	/**
     * @return the video id.
     */
	public long getVideoId(int position) {
		return videoIds[position];
	}
	
	/**
     * @return the video name.
     */
	public String getVideoName(int position) {
		return videoNames.get(position);
	}
	
	/**
     * @return the thumbnail for a video.
     */
	public String getThumbnail(int position) {
		return thumbnailUrls.get(position);
	}
	
	/**
     * @return an array of video names.
     */
	public String[] getVideoNames() {
		return videoNames.toArray(new String[0]);
	}
}
